home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DRIVES.SWG / 0093_Drives unit.pas < prev    next >
Pascal/Delphi Source File  |  1995-02-28  |  4KB  |  114 lines

  1. USES CRT;
  2.  
  3. {
  4. Here is my DRIVES routine again to return all valid drive letters on a
  5. PC. This is a fix from the last version which incorrectly addressed
  6. the local variables and wound up hosing memory. I also added some
  7. extensive comments for readability. Enjoy! }
  8.  
  9. {*****************************************************************************
  10.  * Function ...... Drives
  11.  * Purpose ....... To return a string containing the valid drives for the
  12.  * current system.
  13.  * Parameters .... None
  14.  * Returns ....... A string of the valid drive letters.
  15.  * Notes ......... Rather than changing to each drive to see if it exists, we
  16.  * can instead call DOS Function 26h - Parse a file name.
  17.  * If the file name is invalid (eg, F:), then DOS will say
  18.  * so. So, by testing each drive letter as a file name,
  19.  * DOS will tell us which are good and which are bad!
  20.  * Author ........ Martin Richardson
  21.  * Date .......... August 6, 1993
  22.  * Update ........ 02-01-94: Corrected problem where local VAR variables were
  23.  *  not being used, but a random memory location was
  24.  *  instead!
  25.  * : Added comments for clarity.
  26.  *****************************************************************************}
  27. FUNCTION Drives: STRING; ASSEMBLER;
  28. VAR
  29.   DriveInfo:  ARRAY[1..2] OF CHAR;
  30.   Buffer: ARRAY[1..40] OF CHAR;
  31.   DriveString: ARRAY[1..25] OF CHAR;
  32. ASM
  33.  PUSH  SI { Save Important Registers }
  34.  PUSH  DI
  35.  PUSH  ES
  36.  PUSH  DS
  37.  
  38.  MOV SI, SS { The Stack Segment (SS) points to the }
  39.  MOV DS, SI { VAR's above. Point DS to it... }
  40.  PUSH  DS
  41.  POP ES { ...and ES as well. }
  42.  
  43.  LEA SI, DriveInfo { DS:SI - Where we test each drive letter }
  44.  LEA DI, Buffer { ES:DI - FCB Buffer }
  45.  LEA BX, DriveString{ DS:BX - Our resultant string }
  46.  
  47.  MOV BYTE PTR [SI], '@' { The character before 'A' }
  48.  XOR CX, CX { Zero out CX }
  49.  
  50. @Scan:
  51.  INC BYTE PTR [SI] { Next Drive Letter }
  52.  MOV BYTE PTR [SI+1], ':'
  53.  MOV AX, $2906 { DOS Function 29h - Parse Filename }
  54.  INT 21h {  DS:SI - String to be parsed }
  55.   {  ES:DI - FCB }
  56.  LEA SI, DriveInfo { DS:SI }
  57.  CMP AL, $FF{ AL = FFh if function fails (invalid }
  58.  JE @NotValid { drive letter) }
  59.  
  60.  INC CX { Add one more to our string length... }
  61.  PUSH  CX { ...and save it. }
  62.  MOV CL, BYTE PTR DS:[SI]  { Grab the valid drive letter... }
  63.  MOV [BX], CL  { ...and stuff it into our result }
  64.  INC BX { Next position in result string }
  65.  POP CX { Get our length counter back }
  66.  
  67. @NotValid:
  68.  CMP BYTE PTR [SI], 'Z' { Did we go through all letters? }
  69.  JNE @Scan { Nope, so next letter }
  70.  
  71.  LEA SI, DriveString{ Store DriveString to #Result }
  72.  LES DI, @Result
  73.  INC DI
  74.  REP MOVSB
  75.  
  76.  XCHG  AX, DI { This is the only way to store the }
  77.  MOV DI, WORD PTR @Result  {  length that I can get to work. }
  78.  SUB AX, DI
  79.  DEC AX
  80.  STOSB
  81.  
  82.  POP DS { Restore Important Registers }
  83.  POP ES
  84.  POP DI
  85.  POP SI
  86. END;
  87.  
  88. function DriveValid(Drive: Char): Boolean; assembler;
  89. asm
  90. mov  ah, 19h { Select DOS function 19h }
  91. int  21h { Call DOS for current disk drive }
  92. mov  bl, al { Save drive code in bl }
  93. mov  al, Drive  { Assign requested drive to al }
  94. sub  al, 'A' { Adjust so A:=0, B:=1, etc. }
  95. mov  dl, al { Save adjusted result in dl }
  96. mov  ah, 0eh { Select DOS function 0eh }
  97. int  21h { Call DOS to set default drive }
  98. mov  ah, 19h { Select DOS function 19h }
  99. int  21h { Get current drive again }
  100. mov  cx, 0  { Preset result to False }
  101. cmp  al, dl { Check if drives match }
  102. jne  @@1 { Jump if not--drive not valid }
  103. mov  cx, 1  { Preset result to True }
  104. @@1:
  105. mov  dl, bl { Restore original default drive }
  106. mov  ah, 0eh { Select DOS function 0eh }
  107. int  21h { Call DOS to set default drive }
  108. xchg ax, cx { Return function result in ax }
  109. end;
  110.  
  111. BEGIN
  112.      Clrscr;
  113.      Writeln(Drives);
  114. END.